home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’94 / [√] Distribution Restricted! / Scott Fought, Chad Walters / That Shit's (newer) / ThatShits.a < prev   
Text File  |  1994-06-25  |  4KB  |  152 lines

  1. ; 'That Shits!'
  2. ; Copyright 1994, Scott Fought and Chad Walters
  3. ;
  4. ; Plays sounds as you crash into MacsBug
  5. ; Also, keeps AppleTalk connection while you're in MacsBug
  6. ;
  7. ; Tested with MacsBug 6.5d6 (doesn't work with 6.2.2)
  8. ;
  9. ; Build in MPW using the following:
  10. ;    Asm ThatShits.a
  11. ;    Link ThatShits.a.o -o 'That Shits!' -c 'Sh*t' -t 'INIT' -ra =resSysHeap,resLocked -rt INIT=237
  12. ;
  13. ; Test App:
  14. ;    asm TestShit.a
  15. ;    link TestShit.a.o -o TestShit
  16. ;
  17.  
  18.             MACHINE    MC68020
  19.             
  20.             INCLUDE 'Traps.a'
  21.             INCLUDE 'Sound.a'
  22.             INCLUDE 'SysEqu.a'
  23.  
  24. ResourceStart:        MAIN
  25.     tst.b    MBState
  26.     beq.w    @Exit
  27.  
  28.     lea        (ResourceStart,PC),a0
  29.     _RecoverHandle
  30.     move.l    a0,-(sp)
  31.     _DetachResource                        ; keep this code around (the INIT is locked, system)
  32.     bne.s    @Exit
  33.  
  34.     move.l    TheZone,-(sp)                ; save zone
  35.     move.l    SysZone,TheZone                ; switch to System zone
  36.  
  37.     subq.l    #2,sp                        ; result space
  38.     pea        (mySoundChannel,pc)            ; push pointer to the sound channel record
  39.     move.w    #sampledSynth,-(sp)            ; only going to play sampled sounds
  40.     move.l    #initMono,-(sp)                ; mono channel is fine
  41.     clr.l    -(sp)                        ; no call back
  42.     _SndNewChannel
  43.     move.w    (sp)+,d0                    ; get result
  44.     
  45.     move.l    (sp)+,TheZone                ; restore zone
  46.     
  47.     tst.w    d0                            ; test result
  48.     bne.s    @Exit                        ; exit if channel init fails
  49.     
  50.     move.l    #23701,d6
  51.     moveq    #5-1,d5
  52.     lea        (SoundHandleTable,PC),a3
  53.  
  54. @HandleLoop:
  55.     subq.l    #4,sp                        ; return handle space
  56.     move.l    #'snd ',-(sp)                
  57.     move.w    d6,-(sp)                    
  58.     _Get1Resource
  59.     move.l    (sp)+,d7                    ; did we get it?
  60.     beq.s    @Exit                        ; exit if not
  61.     
  62.     move.l    d7,-(sp)                    ; keep the 'snd ' around (its locked, system)
  63.     _DetachResource
  64.     bne.s    @Exit
  65.  
  66.     move.l    d7,(a3)+
  67.     addq.l    #1,d6
  68.     dbf        d5,@HandleLoop
  69.  
  70.     lea        (ReturnAddressTable,PC),a0
  71.     moveq    #$8,d7
  72.     move.l    d7,a1
  73.     lea        (CrashRoutine,PC),a3
  74.     moveq    #5-1,d7                        ; patch 5 vectors starting at 8
  75. @VectorLoop:
  76.     move.l    (a1),(a0)+                    ; store original value in return table
  77.     move.l    a3,(a1)+                    ; replace with our routine
  78.     dbf        d7,@VectorLoop
  79.     
  80.  
  81.     move.w    #$a08d,d0        ;_DebugUtil
  82.     _GetTrapAddress ,newOS
  83.     lea        (OrigDebugUtil+2,PC),a1
  84.     move.l    a0,(a1)
  85.     move.w    #$a08d,d0        ;_DebugUtil
  86.     lea        (DebugUtil,PC),a0
  87.     _SetTrapAddress ,newOS
  88.     
  89. @Exit:    
  90.     rts
  91.     
  92.  
  93. CrashRoutine:
  94.     move.l    d0,-(sp)
  95.     moveq    #0,d0
  96.     move.b    4+7(sp),d0            ; get the vector offset from the exception stack frame
  97.     subq.w    #8,d0                ; table starts with 8
  98.     move    SR,-(sp)
  99.     andi    #$0700,(sp)+
  100.     bne.s    @DontPlay            ; if so, don't do the sound
  101.         jsr        PlayCrashSound
  102. @DontPlay:
  103.     move.l    (ReturnAddressTable,PC,d0.w),-(sp)    ;Get return address
  104.     move.l    4(sp),d0            ; restore d0
  105.     move.l    (sp)+,(sp)            ; move address down
  106.     rts    
  107.  
  108.  
  109. PlayCrashSound:
  110.     movem.l    d0-d2/a0-a1,-(sp)
  111.  
  112.     subq.l    #2,sp                                ; result space
  113.     move.l    (mySoundChannel,pc),-(sp)            ; use our sound channel
  114.     move.l    (SoundHandleTable,PC,d0.w),-(sp)    ; Get sound handle
  115.     st        -(sp)                                ; asynchronously 
  116.     _SndPlay                                    ; OSErr SndPlay(SndChannelPtr chan, Handle sndHdl, Boolean async)
  117.     addq.l    #2,sp                                ; pop result, don't care
  118.  
  119.     movem.l    (sp)+,d0-d2/a0-a1
  120.     rts
  121.  
  122.  
  123. DebugUtil:
  124.     cmpi.w    #3,d0                                ; is it DebuggerPoll?
  125.     bne.s    OrigDebugUtil                        ; if not, pass through
  126.         movem.l    d0/d1,-(sp)
  127.         move.w    $C74,d0                            ; get interrupt level when we entered MacsBug                            
  128.         andi.w    #$0700,d0
  129.         bne.s    @Out                            ; if so, don't lower interrupts
  130.             move    SR,d0
  131.             move    d0,d1
  132.             andi.w    #$F8FF,d1                    ; mask off current interrupt level    
  133.             move    d1,SR                        ; lower interrupt level
  134.             nop
  135.             move    d0,SR                        ; restore interrupt level
  136.     @Out:
  137.         movem.l    (sp)+,d0/d1
  138. OrigDebugUtil:
  139.     jmp        $12345678
  140.     
  141.  
  142.  
  143. MySoundChannel:                        ; stores pointer to sound channel record
  144.     DC.L    0
  145.  
  146. SoundHandleTable:                    ; table of sounds
  147.     DCB.L    5,0
  148.     
  149. ReturnAddressTable:                    ; table of original vectors
  150.     DCB.L    5,0
  151.     
  152.     END